package com.woniuxy.oa.rms.login.interceptor;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import org.springframework.web.servlet.HandlerInterceptor;
import org.springframework.web.servlet.ModelAndView;

import com.woniuxy.oa.rms.login.listener.RightListener;

public class RightInterceptor implements HandlerInterceptor{

	@Override
	public boolean preHandle(HttpServletRequest request,
			HttpServletResponse response, Object handler) throws Exception {
		HttpSession session = request.getSession();
//		System.out.println("-------》"+session);
		Object object = session.getAttribute("userId");
//		System.out.println("user----->"+object);
		if(object != null){
			return true;
		}
		String uri = request.getRequestURI();
		if(uri.endsWith("/login.jsp") || uri.endsWith("/loginController/login")){
			return true;
		}
		request.getRequestDispatcher("/WEB-INF/views/login.jsp").forward(request, response);
		return false;
	}

	
	
	@Override
	public void postHandle(HttpServletRequest request,
			HttpServletResponse response, Object handler,
			ModelAndView modelAndView) throws Exception {
		
	}

	@Override
	public void afterCompletion(HttpServletRequest request,
			HttpServletResponse response, Object handler, Exception ex)
			throws Exception {
		
	}
	
   

}
